/**
 * [后台角色权限]列表首页[JS]
 * @param $auth 权限
 */
var app = function ($auth) {

    return new Vue({
        el: '#vueContainer',
        data: {
            loadOver: false,
            setting: {
                pageType: 'index', // 页面类型
                showAllSearch: false, // 是否出现[展示全部查询]按钮
                smallScreenWidth: 998, // 小屏幕临界点(px)
                isSmallScreen: false, // 是否是小屏幕
                clearVis: false,  // 清除缓存弹出层
                showClearConfirm: true, // 是否展示信息清除缓存改变弹出层
                zTreeButtonClick: false, // ZTree树形按钮点击
                bodyWidth: document.documentElement.clientWidth, // body宽度
            },
            roleId: null,   // 角色编号
            showTopScroll: false, // 是否已滚动，默认否
            dataList: [],         // 父级数据列表
            handleSelectList: [], // 当前多选项
            searchForm: {
                group: [ // 组合查询
                    {name: 'name', text: '标题'},
                ],
                groupOther: [
                    {name: 'status', type: 'radio', text: '状态'},
                ],         // 组合查询 右侧
                base: [],         // 基础
                more: [],  // 更多
                value: {}  // 值
            },    // 查询表单数据
            transferStyle: {  // 穿梭框样式
                height: 0
            },
            transButtonStyle: {  // 穿梭框样式
                height: 0,
                paddingTop: 0
            },
            roleList: [],       // 角色列表
            haveAuth: {
                dom: null,
                list: [],
                count: 0
            },    // 已经有的权限
            haveNotAuth: {
                dom: null,
                list: [],
                count: 0
            }, // 没有的权限
            pageDialog: {
                show: false,    // 页面 - 是否展示弹出层
                url: '',        // 页面 - 弹出层连接
                loading: false, // 页面 - 弹出层加载中
                isIframe: false // 页面 - 是否[iframe]嵌入
            },
        },
        created: function () {
            // 初始化
            this.init();
            // 获取下设置
            this.getSetting();
            var that = this;
            this.$nextTick(function () {
                // 获取下列表
                that.getList();
                that.loadOver = true;
                that.initMainScroll();
            });
        },
        methods: {
            /**
             * 初始化的逻辑
             */
            init: function () {

                var params = $w.getParams();
                // 是否[iframe]嵌入
                this.pageDialog.isIframe = window.self !== window.top;

                var that = this;
                // [嵌入]返回事件监听 直接走自己的返回
                if (this.pageDialog.isIframe) {
                    window.addEventListener("popstate", function ($event) {
                        if (that.cancel) that.cancel(); // 返回上一页
                        window.history.forward(-1);     // 清理此页历史记录
                    }, false);
                    window.history.pushState({
                        title: "title", url: "#"
                    }, "title", "#");
                    window.history.forward(1);
                }

                this.$nextTick(function () {
                    // 监听主滚动条
                    that.$refs['mainScroller'].wrap.addEventListener('scroll', function ($event) {
                        that.showTopScroll = $event.srcElement.scrollTop > 10; // 顶部以滚动
                    })
                });
            },
            /**
             * 初始化滚动条
             */
            initMainScroll: function () {
                var shadowDom = this.$refs['mainScrollShadow'];
                if (!shadowDom) return false;
                this.$refs.mainScroller.wrap.onscroll = function ($event) {
                    var opacity = 0;
                    opacity = $event['srcElement']['scrollTop'] / 100;
                    opacity = opacity > 0.6 ? 0.6 : opacity
                    shadowDom['$el']['style']['box-shadow'] = '0 5px 15px 0 rgb(204, 204, 204, ' + opacity + ')';
                };
            },
            /**
             * 顶部查询 - 初始化查询[FORM]
             * @returns {boolean}
             */
            initSearchForm: function () {

                // 暂存
                var stage;
                // 赋值默认值
                for (var i in this.setting) {
                    if (!this.setting.hasOwnProperty(i)) continue;
                    // 不存在指定字符串直接返回
                    if (i.indexOf('default_') === -1 && i.indexOf('_list') === -1) continue;

                    // 组合字段右侧 默认值, 值列表
                    for (var x in this.searchForm['groupOther']) {
                        if (!this.searchForm['groupOther'].hasOwnProperty(x)) continue;
                        if (!this.searchForm['groupOther'][x]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['groupOther'][x]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['groupOther'][x], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['groupOther'][x]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['groupOther'][x], 'option',
                                this.setting[i]
                            );
                        }
                    }

                    // 基础字段 默认值, 值列表
                    for (var y in this.searchForm['base']) {
                        if (!this.searchForm['base'].hasOwnProperty(y)) continue;
                        if (!this.searchForm['base'][y]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['base'][y]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['base'][y], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['base'][y]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['base'][y], 'option',
                                this.setting[i]
                            );
                        }
                    }

                    // 更多字段 默认值, 值列表
                    for (var z in this.searchForm['more']) {
                        if (!this.searchForm['more'].hasOwnProperty(z)) continue;
                        if (!this.searchForm['more'][z]) continue;
                        // 字段默认值 键值
                        stage = 'default_' + this.searchForm['more'][z]['name'];
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['more'][z], 'default',
                                this.setting[i]
                            );
                            continue;
                        }

                        // 字段默列表 键值
                        stage = this.searchForm['more'][z]['name'] + '_list';
                        // 相同则需要赋值[默认值]
                        if (stage === i) {
                            this.$set(this.searchForm['more'][z], 'option',
                                this.setting[i]
                            );
                        }
                    }
                }
            },
            /**
             * 获取设置
             * @returns {boolean}
             */
            getSetting: function () {
                // 正在加载...
                var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '加载中...',
                    customClass: 'z-index-top'
                });
                var that = this;

                // 获取各模块的值
                $w.request({
                    url: $w.getApiUrl('adminAuth.setting'),
                    type: 'get',
                    data: {
                        type: 'index' // 首页
                    },
                    dataType: 'json',
                    afterCallback: function () {
                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });
                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }

                        // 挨个赋值[setting]中
                        for (var i in event.data) {
                            if (!event.data.hasOwnProperty(i)) continue;
                            that.$set(that.setting, i, event.data[i]);

                            // 字段是列表值 需要更改键
                            if (i.indexOf('_list') !== -1) {
                                that.setting[i] = $w.array_index(that.setting[i], 'key');
                            }
                        }

                        // 初始化选择查询 字段
                        that.initSearchForm(true);
                    }
                });
            },
            /**
             * 获取下列表
             */
            getList: function ($noLoading) {

                $noLoading = ($noLoading === true) || false;

                // 正在加载...
                if (!$noLoading) {
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '获取中...',
                        customClass: 'z-index-top'
                    });
                }
                var that = this;

                // 获取各模块的值
                $w.request({
                    url: $w.getApiUrl('adminAuth.list'),
                    type: 'get',
                    data: {
                        page: this.page,
                        page_size: this.page_size,
                        search: this.searchForm.value,
                        roleId: this.roleId
                    },
                    dataType: "json",
                    afterCallback: function () {

                    },
                    callback: function (event) {

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg ? event.msg : '操作失败，请稍后尝试'
                            });
                        }

                        // 没有的权限
                        that.haveNotAuth.list = event.data.haveNotAuth;
                        // 有的权限
                        that.haveAuth.list = event.data.haveAuth;
                        // 角色
                        that.roleList = event.data.roleList;

                        that.initTree();

                        // 监测屏幕大小变化s
                        $(window).resize(function () {
                            // ####### 初始化权限框大小 ######
                            // 获取容器的高度
                            var height = $('#mainScroller').height();
                            // 赋值到穿梭框高度
                            that.transferStyle.height = (height * 0.5) + 'px';
                            // 赋值到穿梭框按钮高度
                            that.transButtonStyle.height = (height * 0.5) + 'px';
                            // 赋值到穿梭框按钮
                            that.transButtonStyle.paddingTop = (height * 0.5) / 3 + 'px';

                            // 超过此宽度展示 更多筛选
                            var bodyDom = document.getElementsByTagName('body');
                            if (bodyDom[0] &&
                                bodyDom[0].clientWidth <= that.setting.smallScreenWidth
                            ) {
                                return that.setting.isSmallScreen = true;
                            }
                            return that.setting.isSmallScreen = false;
                        }).resize();

                        that.$nextTick(function () {

                            // 隐藏正在加载
                            if (!$noLoading) {
                                // 调用下查询
                                searchNodeLazy(that.searchForm.label);
                                loadingInstance.close();
                            }

                            // 初始化了给 节点添加[class]
                            that.addDisabledCss();
                            // 重新加载下 已获取数量
                            that.reloadHaveCount();
                            // 重新加载下 未获取数量
                            that.reloadHaveNotCount();
                        });
                    }
                });
            },
            /**
             * 强制刷新
             * @param $noLoading
             */
            reload: function ($noLoading) {

                var that = this;

                this.$confirm('确定要刷新权限吗(将重新获取文件内权限信息), 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    $noLoading = $noLoading || false;

                    // 正在加载...
                    if (!$noLoading) {
                        var loadingInstance = ELEMENT.Loading.service({
                            fullscreen: false,
                            text: '加载中...',
                            customClass: 'z-index-top'
                        });
                    }

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminAuth.reload'),
                        type: 'get',
                        data: {
                            page: this.page,
                            page_size: this.page_size,
                            search: this.searchForm
                        },
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                if (!$noLoading) {
                                    // 调用下查询
                                    searchNodeLazy(that.searchForm.label);
                                    loadingInstance.close();
                                }
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 没有的权限
                            that.haveNotAuth.list = event.data.haveNotAuth;
                            // 有的权限
                            that.haveAuth.list = event.data.haveAuth;
                            // 角色
                            that.roleList = event.data.roleList;

                            that.initTree();
                        }
                    });
                });
            },
            /**
             * 初始化树形插件
             */
            initTree: function () {
                var that = this;

                var setting = {
                    data: {
                        keep: {
                            parent: true,
                        }
                    },
                    check: {
                        enable: true,
                        nocheckInherit: true,
                        chkDisabledInherit: true
                    },
                    edit: {
                        enable: true,
                        drag: {
                            isMove: true
                        },
                        showRemoveBtn: false, // 不展示移除按钮
                        showRenameBtn: false // 不展示重命名按钮
                    },
                    view: {
                        nameIsHTML: true, // 允许name支持html - 模糊查询
                        addHoverDom: this.addHoverDom,
                        removeHoverDom: this.removeHoverDom,
                        nodeClasses: this.getNodeClass
                    },
                    callback: {
                        onRename: this.renameItem,
                        onExpand: this.zTreeOnExpand,
                        onClick: this.zTreeOnClick
                    }
                };
                // 已有权限树
                this.haveAuth.dom = $.fn.zTree.init($('#haveTreeDemo'), setting,
                    this.haveAuth.list);
                // 暂无权限树
                this.haveNotAuth.dom = $.fn.zTree.init($('#notHaveTreeDemo'), setting,
                    this.haveNotAuth.list);
                window.jqueryZtreeFuzzysearch('notHaveTreeDemo', '#worldSearch',
                    null, true); //初始化模糊搜索方法
                this.$nextTick(function () {
                    $('#worldSearch').change();
                });
            },
            /**
             * 保存全部权限
             */
            saveAuth: function () {

                var auth = this.haveAuth.dom.transformToArray(this.haveAuth.dom.getNodes()),
                    stageAuth = [];
                for (var i in auth) {
                    if (!auth.hasOwnProperty(i)) continue;
                    // 父级菜单直接过滤掉
                    if (auth[i]['isParent']) continue;
                    stageAuth.push(auth[i]['id']);
                }

                // 未选择角色
                if (!this.roleId || this.roleId < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择角色'
                    });
                }

                var that = this;
                this.$confirm('确定要保存这' + stageAuth.length + '个权限吗, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '保存中...',
                        customClass: 'z-index-top'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminAuth.saveAuth'),
                        type: 'POST',
                        data: {
                            roleId: that.roleId,
                            authId: stageAuth
                        },
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;

                            // 成功 加载下列表
                            return that.$nextTick(function () {
                                // 隐藏正在加载
                                that.getList(true);
                                that.dataChange();
                            });
                        },
                    });
                });
            },
            /**
             * 重置全部权限
             */
            allAuthReset: function () {},
            /**
             * [zTree]元素编辑名称
             * @param $dom
             * @returns {boolean}
             */
            renameItem: function ($dom) {

                // 树形按钮点击了
                this.setting.zTreeButtonClick = true;
                var id, text = '';
                if (!$dom || $dom.length <= 0) {
                    id = this.getSelectNodesId()
                } else {
                    id = $($dom['target']).data('id');
                }

                var oldName = $($dom['target']).data('name');
                var that = this;

                this.$prompt('请输入要修改的新名字', '修改权限名称', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    cancelButtonClass: 'el-button--danger',
                    inputValue: oldName,
                    inputValidator: function ($val) {
                        if (!$val || $val.length < 1) return '请输入名称';
                        if ($val === oldName) return '输入的名称和旧名称相同';
                        return true;
                    },
                    inputErrorMessage: '请输入正确的名称',
                    type: 'warning'
                }).then(function ($name) {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '提交中...',
                        customClass: 'z-index-top'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminAuth.rename'),
                        type: 'POST',
                        data: {idList: id, name: $name['value']},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                                // 树形按钮点击了 - 否
                                that.setting.zTreeButtonClick = false;
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;

                            // 成功 加载下列表
                            return that.$nextTick(function () {
                                // 隐藏正在加载
                                that.getList();
                            });
                        }
                    });
                }).catch(function () {
                    // 树形按钮点击了 - 否
                    that.setting.zTreeButtonClick = false;
                });
            },
            /**
             * [zTree]元素禁用
             * @param $dom
             * @returns {boolean}
             */
            disabledItem: function ($dom) {

                // 树形按钮点击了
                this.setting.zTreeButtonClick = true;
                var id, text = '';
                if (!$dom || $dom.length <= 0) {
                    id = this.getSelectNodesId()
                } else {
                    id = $($dom['target']).data('id');
                }

                if (!id || id.length <= 0) {
                    this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择一个权限重试'
                    });
                    return false;
                }

                var that = this;
                this.$confirm('确定要禁用权限吗(父级禁用其子集也将禁用), 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '禁用中...',
                        customClass: 'z-index-top'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminAuth.disabled'),
                        type: 'POST',
                        data: {idList: id},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                                // 树形按钮点击了 - 否
                                that.setting.zTreeButtonClick = false;
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;

                            // 成功 加载下列表
                            return that.$nextTick(function () {
                                // 隐藏正在加载
                                that.getList();
                                that.dataChange();
                            });
                        }
                    });
                }).catch(function () {
                    // 树形按钮点击了 - 否
                    that.setting.zTreeButtonClick = false;
                });
            },
            /**
             * [zTree]元素开启
             * @param $dom
             * @returns {boolean}
             */
            openItem: function ($dom) {

                // 树形按钮点击了
                this.setting.zTreeButtonClick = true;
                var id, text;
                if (!$dom || $dom.length <= 0) {
                    id = this.getDisabledNodesId();
                    text = '全部已禁用权限';
                } else {
                    id = $($dom['target']).data('id');
                    text = '已选权限';
                }

                if (!id || id.length <= 0) {
                    this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择一个权限重试'
                    });
                    return false;
                }

                var that = this;
                this.$confirm('确定要开启权限(' + text + '且父级开启其子集也将开启), 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '开启中...',
                        customClass: 'z-index-top'
                    });

                    // 获取各模块的值
                    $w.request({
                        url: $w.getApiUrl('adminAuth.open'),
                        type: 'POST',
                        data: {idList: id},
                        dataType: "json",
                        afterCallback: function () {
                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                                // 树形按钮点击了 - 否
                                that.setting.zTreeButtonClick = false;
                            });
                        },
                        callback: function (event) {

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg ? event.msg : '操作失败，请稍后尝试'
                                });
                            }

                            // 放空列表
                            that.handleSelectList = null;

                            // 成功 加载下列表
                            return that.$nextTick(function () {
                                // 隐藏正在加载
                                that.getList();
                                that.dataChange();
                            });
                        }
                    });
                }).catch(function () {
                    // 树形按钮点击了 - 否
                    that.setting.zTreeButtonClick = false;
                });
            },
            /**
             * 获取已点选节点的编号
             */
            getSelectNodesId: function () {
                var haveList = $.fn.zTree.getZTreeObj('haveTreeDemo').getCheckedNodes(),
                    haveNotList = $.fn.zTree.getZTreeObj('notHaveTreeDemo').getCheckedNodes(),
                    idList = [];
                for (var i in haveList) {
                    // 验证[key]是否存在
                    if (!haveList.hasOwnProperty(i)) continue;
                    if (!haveList[i] || !haveList[i]['id']) {
                        continue;
                    }
                    idList.push(haveList[i]['id']);
                }
                for (i in haveNotList) {
                    // 验证[key]是否存在
                    if (!haveNotList.hasOwnProperty(i)) continue;
                    if (!haveNotList[i] || !haveNotList[i]['id']) {
                        continue;
                    }
                    idList.push(haveNotList[i]['id']);
                }
                return idList;
            },
            /**
             * 获取[已禁用]节点的编号
             */
            getDisabledNodesId: function () {
                var haveList = $.fn.zTree
                        .getZTreeObj('haveTreeDemo')
                        .getNodesByParam('chkDisabled', true),
                    haveNotList = $.fn.zTree
                        .getZTreeObj('notHaveTreeDemo')
                        .getNodesByParam('chkDisabled', true),
                    idList = [];
                for (var i in haveList) {
                    // 验证[key]是否存在
                    if (!haveList.hasOwnProperty(i)) continue;
                    if (!haveList[i] || !haveList[i]['id']) {
                        continue;
                    }
                    idList.push(haveList[i]['id']);
                }
                for (i in haveNotList) {
                    // 验证[key]是否存在
                    if (!haveNotList.hasOwnProperty(i)) continue;
                    if (!haveNotList[i] || !haveNotList[i]['id']) {
                        continue;
                    }
                    idList.push(haveNotList[i]['id']);
                }
                return idList;
            },
            /**
             * 获取节点[class]名称|循环每个节点
             * @param $treeId
             * @param $treeNode
             * @returns {string}
             */
            getNodeClass: function ($treeId, $treeNode) {
                if ($treeNode.chkDisabled === true) {
                    return 'disabled-tree-item'
                }
            },
            /**
             * 全选、全取消节点
             * @param $type
             * @param $dom
             */
            checkCancelAll: function ($type, $dom) {
                $.fn.zTree.getZTreeObj($dom).checkAllNodes($type);
            },
            /**
             * 打开、关闭节点
             * @param $type
             * @param $dom
             */
            openCloseAll: function ($type, $dom) {
                $.fn.zTree.getZTreeObj($dom).expandAll($type);
                // 首先给禁用的对象添加[class]
                this.addDisabledCss();
            },
            /**
             * 给节点添加[class]
             */
            addDisabledCss: function () {
                // 加载下禁用的节点
                var nodeList = $.fn.zTree.getZTreeObj('notHaveTreeDemo')
                    .getNodesByParam('chkDisabled', true);
                nodeList = $w.eachAdd(nodeList, $.fn.zTree.getZTreeObj('haveTreeDemo')
                    .getNodesByParam('chkDisabled', true));
                for (var i in nodeList) {
                    // 验证[key]是否存在
                    if (!nodeList.hasOwnProperty(i)) continue;
                    $('#' + nodeList[i]['tId'] + '_span').addClass('disabled-tree-item');
                }
            },
            /**
             * 鼠标移动到[zTree]元素 - 添加节点自定义按钮
             * @param $treeId
             * @param $treeNode
             */
            addHoverDom: function ($treeId, $treeNode) {

                var adderDom = $("#" + $treeNode['tId'] + '_a'), // 要操作容器
                    addHtml = '',  // 最终添加[HTML]

                    btnRenameId = "btnRename_" + $treeNode.id, // [重命名]按钮的[ID]
                    btnRenameDom = $('#' + btnRenameId), // [重命名]按钮的[Dom]

                    btnRemId = "btnRem_" + $treeNode.id, // [删除]按钮的[ID]
                    btnRemDom = $('#' + btnRemId), // [删除]按钮的[Dom]

                    btnOpenId = "btnOpen_" + $treeNode.id, // [恢复]按钮的[ID]
                    btnOpenDom = $('#' + btnOpenId) // [恢复]按钮的[Dom]
                ;

                // 如果是[重命名]按钮没有 - 展示[重命名]按钮
                if (btnRenameDom.length <= 0 && $auth.rename) {
                    addHtml += "<span id='btnRename_" + $treeNode.id + "' class='el-icon-edit'" +
                        " title='重命名[" + $treeNode.name + "]' data-id=" + $treeNode.id +
                        " data-name='" + $treeNode.name + "'></span>";
                }

                var settingStatus = this.setting.status_list;
                var status = parseInt($treeNode['status']);
                // 如果是[开启] - 展示[禁用]按钮
                if (status === settingStatus.open && btnRemDom.length <= 0 && $auth.disabled) {
                    addHtml +=
                        "<span id='btnRem_" + $treeNode.id + "' class='el-icon-error'" +
                        " title='禁用[" + $treeNode.name + "]' data-id=" + $treeNode.id + "></span>";
                }

                // 如果是[禁用] - 展示[开启]按钮
                if (status === settingStatus.disabled && btnOpenDom.length <= 0 && $auth.open) {
                    addHtml +=
                        "<span id='btnOpen_" + $treeNode.id + "' class='el-icon-success'" +
                        " title='开启[" + $treeNode.name + "]' data-id=" + $treeNode.id + "></span>";
                }

                // 添加[HTML]
                adderDom.append(addHtml);

                // 如果添加了[移除]元素 - 绑定方法
                if (btnRemDom) {
                    // 尝试移除下[禁用]绑定的方法
                    $("#btnRem_" + $treeNode.id).unbind();
                    btnRemDom.bind("click", this.disabledItem);
                }

                // 如果添加了[开启]元素 - 绑定方法
                if (btnOpenDom) {
                    // 尝试移除下[开启]绑定的方法
                    $("#btnOpen_" + $treeNode.id).unbind();
                    btnOpenDom.bind("click", this.openItem);
                }

                // 如果添加了[重命名]元素 - 绑定方法
                if (btnRenameDom) {
                    // 尝试移除下[重命名]绑定的方法
                    $("#btnRename_" + $treeNode.id).unbind();
                    btnRenameDom.bind("click", this.renameItem);
                }
            },
            /**
             * 鼠标移动出[zTree]元素
             * @param $treeId
             * @param $treeNode
             */
            removeHoverDom: function ($treeId, $treeNode) {
                // 尝试移除下[禁用]元素
                $("#btnRem_" + $treeNode.id).unbind().remove();
                // 尝试移除下[开启]元素
                $("#btnOpen_" + $treeNode.id).unbind().remove();
                // 尝试移除下[重命名]元素
                $("#btnRename_" + $treeNode.id).unbind().remove();
            },
            /**
             * 监测节点展开
             * @param $event
             * @param $treeId
             * @param $treeNode
             */
            zTreeOnExpand: function ($event, $treeId, $treeNode) {
                // 首先给禁用的对象添加[class]
                this.addDisabledCss();
            },
            /**
             * 监测节点展开 点击
             * @param $event
             * @param $treeId
             * @param $treeNode
             */
            zTreeOnClick: function ($event, $treeId, $treeNode) {
                // 点击了按钮返回下
                if (this.setting.zTreeButtonClick) return false;
                var title = $treeNode['name'];
                var html = '<p><label class="import-text">权限名：</label><span>' + title + '</span></p>';

                var stage = $treeNode['url'];
                html +=
                    '<p>' +
                    '<label class="import-text">权限连接：</label>' +
                    '<a href="' + stage + '" class="auth-show-url" target="_blank">' +
                    stage +
                    '</a>' +
                    '</p>';

                stage = $treeNode['route'];
                html += '<p><label class="import-text">路由：</label><span>' + stage + '</span></p>';

                stage = $treeNode['status_text'];
                html += '<p><label class="import-text">状态：</label><span>' + stage + '</span></p>';

                this.$alert(html, '【' + title + '】', {
                    dangerouslyUseHTMLString: true,
                    closeOnClickModal: true,
                    lockScroll: true
                });
            },
            /**
             * 将左侧未获取权限转移到右侧已获取权限
             */
            toHave: function () {

                var haveNotObj = this.haveNotAuth.dom,
                    haveNotChkList = haveNotObj.getCheckedNodes(true),
                    haveObj = this.haveAuth.dom;

                // 未获取权限是否有选择
                if (haveNotChkList.length < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择一个[未获得的权限]'
                    });
                }

                // 未选择角色
                if (!this.roleId || this.roleId < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择角色'
                    });
                }

                var item, parentNode, haveParentNode;
                for (var i in haveNotChkList) {

                    // 验证[key]是否存在
                    if (!haveNotChkList.hasOwnProperty(i)) continue;

                    item = haveNotChkList[i];
                    // 父级 先不操作
                    if (item['isParent']) continue;

                    // 先拿出父级
                    parentNode = item.getParentNode();
                    // 父级是空的直接报错吧
                    if (!parentNode) {
                        return this.$message({
                            type: 'error',
                            showClose: true,
                            message: '[' + item['name'] + ']的父级不存在，请刷新权限'
                        });
                    }

                    // 获取下已获得权限那边 有没有对应的父级
                    haveParentNode = haveObj.getNodesByParam('id', parentNode['id']);
                    // 没有创建
                    if (!haveParentNode || haveParentNode.length < 1) {
                        haveParentNode = haveObj.addNodes(null, [
                            {
                                id: parentNode['id'],
                                name: parentNode['name'],
                                parent_id: parentNode['parent_id'],
                                content: parentNode['content'],
                                add_time: parentNode['add_time'],
                                module: parentNode['module'],
                                controller: parentNode['controller'],
                                action: parentNode['action'],
                                route: parentNode['route'],
                                status: parentNode['status'],
                                url: parentNode['url'],
                                sort: parentNode['sort'],
                                status_text: parentNode['status_text'],
                                isParent: parentNode['isParent'],
                                chkDisabled: parentNode['chkDisabled']
                            }
                        ]);
                    }

                    // 再去获取下 - 第[0]个
                    haveParentNode = haveParentNode[0];

                    // 父级再是空的 直接报错吧
                    if (!haveParentNode) {
                        return this.$message({
                            type: 'error',
                            showClose: true,
                            message: '[' + parentNode['name'] + ']添加失败，请刷新权限'
                        });
                    }

                    // 当前循环的子集信息添加到里面儿
                    haveObj.addNodes(haveParentNode, [
                        {
                            id: item['id'],
                            name: item['name'],
                            parent_id: item['parent_id'],
                            content: item['content'],
                            add_time: item['add_time'],
                            module: item['module'],
                            controller: item['controller'],
                            action: item['action'],
                            route: item['route'],
                            status: item['status'],
                            url: item['url'],
                            sort: item['sort'],
                            status_text: item['status_text'],
                            isParent: item['isParent'],
                            chkDisabled: item['chkDisabled']
                        }
                    ]);

                    // 即已添加删除下自身
                    haveNotObj.removeNode(item);

                    // 此时重新加载下子集列表 - 没了 就删除父级
                    parentNode = haveNotObj.getNodeByTId(parentNode['tId']);
                    if (!parentNode['children'] || parentNode['children'].length < 1) {
                        haveNotObj.removeNode(parentNode);
                    }
                }
                // 重新加载下 已获取数量
                this.reloadHaveCount();
                // 重新加载下 未获取数量
                this.reloadHaveNotCount();
            },
            /**
             * 将左侧未获取权限转移到右侧已获取权限
             */
            toHaveNot: function () {

                var haveObj = this.haveAuth.dom,
                    haveChkList = haveObj.getCheckedNodes(true),
                    haveNotObj = this.haveNotAuth.dom;

                // 未获取权限是否有选择
                if (haveChkList.length < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择一个[已获得的权限]'
                    });
                }

                // 未选择角色
                if (!this.roleId || this.roleId < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择角色'
                    });
                }

                var item, parentNode, haveNotParentNode;
                for (var i in haveChkList) {

                    // 验证[key]是否存在
                    if (!haveChkList.hasOwnProperty(i)) continue;

                    item = haveChkList[i];
                    // 父级 先不操作
                    if (item['isParent']) continue;

                    // 先拿出父级
                    parentNode = item.getParentNode();
                    // 父级是空的直接报错吧
                    if (!parentNode) {
                        return this.$message({
                            type: 'error',
                            showClose: true,
                            message: '[' + item['name'] + ']的父级不存在，请刷新权限'
                        });
                    }

                    // 获取下已获得权限那边 有没有对应的父级
                    haveNotParentNode = haveNotObj.getNodesByParam('id', parentNode['id']);
                    // 没有创建
                    if (!haveNotParentNode || haveNotParentNode.length < 1) {
                        haveNotParentNode = haveNotObj.addNodes(null, [
                            {
                                id: parentNode['id'],
                                name: parentNode['name'],
                                parent_id: parentNode['parent_id'],
                                content: parentNode['content'],
                                add_time: parentNode['add_time'],
                                module: parentNode['module'],
                                controller: parentNode['controller'],
                                action: parentNode['action'],
                                route: parentNode['route'],
                                status: parentNode['status'],
                                url: parentNode['url'],
                                sort: parentNode['sort'],
                                status_text: parentNode['status_text'],
                                isParent: parentNode['isParent'],
                                chkDisabled: parentNode['chkDisabled']
                            }
                        ]);
                    }

                    // 再去获取下 - 第[0]个
                    haveNotParentNode = haveNotParentNode[0];

                    // 父级再是空的 直接报错吧
                    if (!haveNotParentNode) {
                        return this.$message({
                            type: 'error',
                            showClose: true,
                            message: '[' + parentNode['name'] + ']添加失败，请刷新权限'
                        });
                    }

                    // 当前循环的子集信息添加到里面儿
                    haveNotObj.addNodes(haveNotParentNode, [
                        {
                            id: item['id'],
                            name: item['name'],
                            parent_id: item['parent_id'],
                            content: item['content'],
                            add_time: item['add_time'],
                            module: item['module'],
                            controller: item['controller'],
                            action: item['action'],
                            route: item['route'],
                            status: item['status'],
                            url: item['url'],
                            sort: item['sort'],
                            status_text: item['status_text'],
                            isParent: item['isParent'],
                            chkDisabled: item['chkDisabled']
                        }
                    ]);

                    // 即已添加删除下自身
                    haveObj.removeNode(item);

                    // 此时重新加载下子集列表 - 没了 就删除父级
                    parentNode = haveObj.getNodeByTId(parentNode['tId']);
                    if (!parentNode['children'] || parentNode['children'].length < 1) {
                        haveObj.removeNode(parentNode);
                    }
                }
                // 重新加载下 已获取数量
                this.reloadHaveCount();
                // 重新加载下 未获取数量
                this.reloadHaveNotCount();
            },
            /**
             * 加载下 已获取数量
             */
            reloadHaveCount: function () {
                var list = this.haveAuth.dom.getNodes();
                var counter = 0;
                for (var i in list) {
                    if (!list.hasOwnProperty(i)) continue;
                    if (!list[i] || !list[i]['children'] || list[i]['children'].length < 1) {
                        continue;
                    }
                    counter = counter + list[i]['children'].length;
                }

                // 赋值
                this.haveAuth.count = $w.dataNoBind(counter);
            },
            /**
             * 加载下 未获取数量
             */
            reloadHaveNotCount: function () {
                var list = this.haveNotAuth.dom.getNodes();
                var counter = 0, i = 0;
                for (i in list) {
                    if (!list.hasOwnProperty(i)) continue;
                    if (!list[i] || !list[i]['children'] || list[i]['children'].length < 1) continue;
                    counter = counter + list[i]['children'].length;
                }

                // 赋值
                this.haveNotAuth.count = $w.dataNoBind(counter);
            },
            /**
             * 监测角色一个选择变化
             */
            handleCheckedRole: function ($value) {
                var checkedCount = $value.length;
                var nowListLength = this.clearRoleInfo.dataList.length;
                this.clearRoleInfo.checkAll = checkedCount === nowListLength;
                this.clearRoleInfo.isIndeterminate = checkedCount > 0 && checkedCount < nowListLength;
            },
            /**
             * 监测 当列表数据改变
             */
            dataChange: function () {
                var that = this;
                // 提示是否调用刷新缓存
                this.$confirm('您已改变数据刷新缓存后才会生效，是否选择角色刷新缓存？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '本次操作不再提示',
                    type: 'warning',
                    dangerouslyUseHTMLString: true,
                    distinguishCancelAndClose: true
                }).then(function () {
                    that.showClearDialog(true);
                });
            },
            /**
             * 清除缓存 - 展示清除角色缓存弹出层
             */
            showClearDialog: function () {

                // 取出[ref]对象
                var cacheCache = this.$refs['clearCache'];
                cacheCache.showDialog = true;
            },
            /**
             * 跳转到首页
             */
            goToIndex: function () {
                // 父级
                var parent = window.parent.top;
                if (!parent) return false;

                // 父级[vue]对象
                var vueInstance = parent.instance;
                if (!parent || !(typeof vueInstance === 'object')) return false;

                // 键值
                var key = vueInstance.tab.indexKey;
                // 操作点击
                $(parent.document).find('#tab-' + key).click();
            },
        },
        watch: {
            /**
             * 监测文本过滤
             * @param $val
             */
            'searchForm.label': function ($val) {
                // this.$refs.tree.filter($val);
            }
        },
        computed: {
            /**
             * 获得顶部样式
             */
            getTopClass: function () {
                var className = [];
                // 如果已经滚动
                if (this.showTopScroll) className.push('is-scroll');

                return className.join(' ');
            }
        },
    });
};
